package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpService empService;

//    @GetMapping
//    public Result EmpList(@RequestParam(defaultValue = "1") Integer page ,
//                          @RequestParam(defaultValue = "10") Integer pageSize) {
//        PageBean pageBean = empService.Page(page,pageSize);
//        return Result.success(pageBean);
//    }

    /**
     * 条件查询员工
     * @param empQueryParam
     * @return
     */
    @GetMapping
    public Result EmpList(EmpQueryParam empQueryParam) {
        log.info("请求参数： {}", empQueryParam);
        PageBean pageBean = empService.Page(empQueryParam);
        return Result.success(pageBean);
    }

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        log.info("新增员工，员工信息：{}", emp);

        empService.save(emp);
        return Result.success();
    }

    /**
     * 批量删除员工
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result EmpDelete(@RequestParam List<Integer> ids){
        log.info("删除员工，员工id：{}", ids);
        empService.EmpDelete(ids);
        return Result.success();
    }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result EmpById(@PathVariable Integer id){
        log.info("根据id查询员工信息，id：{}", id);
        Emp emp = empService.EmpById(id);
        return Result.success(emp);
    }

    /**
     * 修改员工信息
     * @param emp
     * @return
     */
    @PutMapping
    public Result EmpUpdate(@RequestBody Emp emp){
        log.info("修改员工信息，员工信息：{}", emp);
        empService.EmpUpdate(emp);
        return Result.success();
    }

    /**
     * 获取班主任信息
     * @return
     */
    @GetMapping("/list")
    public Result MasterList(){

        List<Emp> masterList = empService.MasterList();
        return Result.success(masterList);
    }

}
